<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<!--add by iBatisTool ClientInfo-->
<sqlMap namespace="${model.initUpperName}">

	<resultMap id="result" class="${model.packageName}.domain.${model.initUpperName}">
		<#list model.fields as field>
		<result property="${field.name}" column="${field.dbName}" />
		</#list>
	</resultMap>

	<!-- 查询条件 -->
	<sql id="query-conditions">
		<dynamic prepend="where">
			<#list model.fields as field>
			<isNotEmpty prepend="and" property="${field.name}">
				t.${field.dbName} = #${field.name}#
			</isNotEmpty>
			</#list>
		</dynamic>
	</sql>

	<!-- 分页查询 取记录数-->
	<select id="select-count" resultClass="int" parameterClass="${model.packageName}.domain.${model.initUpperName}">
		select count(1)
		  from ${model.dbName} t
		<include refid="query-conditions"/>
	</select> 
	
	<!--分页查询 List列表-->	
	<select id="select" resultMap="result" parameterClass="${model.packageName}.domain.${model.initUpperName}">
        select 
			<#list model.fields as field>
			t.${field.dbName}<#sep>,</#sep>
			</#list>
          from ${model.dbName} t
		<include refid="query-conditions"/>
	</select>
	
	<!-- add method insert-->
	<insert id="insert" parameterClass="${model.packageName}.domain.${model.initUpperName}">
  		insert into ${model.dbName}(
  			<#list model.fields as field>
  			${field.dbName}<#sep>,</#sep> 
  			</#list>
  			) 
  		values(
  			<#list model.fields as field>
  			#${field.name}#<#sep>,</#sep> 
  			</#list>
  			)
	</insert>
	<!-- add method update-->
	<update id="update" parameterClass="${model.packageName}.domain.${model.initUpperName}">
		update ${model.dbName} t
		<dynamic prepend="set">
			<#list model.fields as field>
			<isNotEmpty prepend="," property="${field.name}"> t.${field.dbName} = #${field.name}# </isNotEmpty>
			</#list>
		</dynamic>
  		<include refid="query-conditions"/>
	</update>
	<!-- add method delete-->
	<delete id="delete" parameterClass="${model.packageName}.domain.${model.initUpperName}">
  		delete from ${model.dbName} t 
		<include refid="query-conditions"/>
	</delete>	
	
</sqlMap>